package ogmios.components.munches;

import java.io.*;
import ogmios.core.*;

/**
 * A wrapper around another Context. The main purpose of this class is when you need output from invoking a certain command to be printed onto the wrapped context,<br>
 * but you want the underlying context's variables, e.g. the current working directory.
 */
public class ContextWrapper implements Context
{
  private final Context parent;
  private String cwd;
  public ContextWrapper(Context parent)
  {
    this(parent, parent.getCurrentWorkingDirectory());
  }
  public ContextWrapper(Context parent, String cwd)
  {
    this.parent = parent;
    this.cwd = cwd;
  }
   public void print(String message)
   {
     parent.print(message);
   }
    public void println(String message)
    {
      parent.println(message);
    }
   public void setCurrentWorkingDirectory(String newCurrentWorkingDirectory)
   {
     File cwd = OgmiosUtilities.resolvedFile(newCurrentWorkingDirectory, this.cwd);
     if (cwd.exists() && cwd.isDirectory())
     {
      this.cwd = cwd.getAbsolutePath();
     }
    }
    public String getCurrentWorkingDirectory()
    {
      return cwd;
     }

}
